package org.leumasjaffe.initiativeTracker.event;

import static org.leumasjaffe.initiativeTracker.operator.InitiativeController.tracker;

import java.awt.event.ActionEvent;

import javax.swing.Action;

import org.leumasjaffe.initiativeTracker.Constants;

import edu.wpi.heineman.xml.Message;
import edu.wpi.heineman.client.ServerAccess;

@SuppressWarnings("serial")
public class RollInitAction extends InitiativeTrackerAction implements Action {
	
	public RollInitAction (String text) {
		super(text);
	}

	@SuppressWarnings("null")
	@Override
	public void actionPerformed(ActionEvent e) {
		tracker(Constants.id).reroll();
		
		String xmlString = Message.requestHeader() + "<rollRequest game='" + Constants.id + "'>";
		for (int id : list.keyset()) {
			xmlString += "<target id='" + id + "' value='" +
						list.lookup(id).getCharacter().getInit() + "'/>";
		}
		xmlString += "</rollRequest></request>";
		if (xmlString.contains("target"))
			ServerAccess.getInstance().sendRequest(new Message(xmlString));
		
		gui.repage();
		gui.repaint();
	}
	
}
